﻿// 功能：标题栏控件
// 描述：
// 作者：温伟鹏
// 日期：2010/6/7 14:28:34

using System;
using System.Runtime.InteropServices;
using MeizuSDK.Drawing;

namespace MeizuSDK.Presentation
{
    /// <summary>
    /// 标题栏控件
    /// </summary>
    public class HeadingBar : Control
    {
        #region DllImport
        [DllImport("MZFCWrapper.dll")]
        private static extern IntPtr UiHeadingBarWrapperCtor(PaintWinFunc onPaintWin);
        [DllImport("MZFCWrapper.dll")]
        private static extern void UiHeadingBarWrapperDefaultPaintWin(IntPtr pObj, IntPtr hdcDst, ref RECT prcWin, ref RECT prcUpdate);
        [DllImport("MZFCWrapper.dll")]
        private static extern string UiHeadingBarWrapperGetBarText(IntPtr pObj);
        [DllImport("MZFCWrapper.dll")]
        private static extern void UiHeadingBarWrapperSetBarText(IntPtr pObj, [In] [MarshalAs(UnmanagedType.LPWStr)]string strText);
        #endregion

        #region 公共属性
        /// <summary>
        /// 获取或设置标题栏控件的高度
        /// </summary>
        public override System.Drawing.Size Size
        {
            get
            {
                return base.Size;
            }
            set
            {
                System.Drawing.Size size = value;

                if(size.Height!=Screen.TaskBarHeight)
                {
                    size.Height = Screen.TaskBarHeight;
                }

                base.Size = size;
            }
        }
        /// <summary>
        /// 获取或设置标题栏控件的高度
        /// </summary>
        public override int Height
        {
            get
            {
                return base.Height;
            }
            set
            {
                if (value != Screen.TaskBarHeight)
                    return;
                base.Height = Screen.TaskBarHeight;
            }
        }
        /// <summary>
        /// 获取或设置控件显示的文本
        /// </summary>
        public override string Text
        {
            get
            {
                return UiHeadingBarWrapperGetBarText(Handle);
            }
            set
            {
                UiHeadingBarWrapperSetBarText(Handle, value);
            }
        }
        #endregion

        #region 构造函数
        /// <summary>
        /// 构造标题栏控件
        /// </summary>
        public HeadingBar()
        {
            Handle = UiHeadingBarWrapperCtor(PaintWinDelegate);
            SetID();
            Size = new System.Drawing.Size(Screen.Width, MzMetrics.MZM_HEIGHT_HEADINGBAR);
        }
        #endregion

        #region 函数
        /// <summary>
        /// 由系统绘制控件
        /// </summary>
        /// <param name="hdcDst">设备上下文</param>
        /// <param name="prcWin">控件所在区域</param>
        /// <param name="prcUpdate">更新区域</param>
        protected override void OnDefaultPaintWin(IntPtr hdcDst, ref MeizuSDK.Drawing.RECT prcWin, ref MeizuSDK.Drawing.RECT prcUpdate)
        {
            UiHeadingBarWrapperDefaultPaintWin(Handle, hdcDst, ref prcWin, ref prcUpdate);
        }
        #endregion
    }
}
